export const Local = {
    // 设置永久缓存
    set (key, value) {
        if(!key && !value) {
            console.error(new Error('function setStorage params is undefined'))
            return
        }
    
        if(typeof value === 'object') {
            const jsonString = JSON.stringify(value)
            window.localStorage.setItem(key, jsonString)
        }else {
            window.localStorage.setItem(key, value)
        }
      
    },
    // 获取永久缓存
    get (key) {
        if(!key) {
            console.error(new Error('function getStorage params is undefined'))
            return
        }
      
        const value = window.localStorage.getItem(key)
        try {
            const object = JSON.parse(value)
            return object
        } 
        catch (error) {
            return value
        }

    },
    // 移除永久缓存
    remove (key) {
        if(!key) {
            console.error(new Error('function removeStorage params is undefined'))
            return
          }
          window.localStorage.removeItem(key)
    },
    // 移除全部永久缓存
    clear () {
      window.localStorage.clear();
    },
  };